package com.redrose.audioandvideo;


import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.viewpager.widget.PagerAdapter;
import com.redrose.audioandvideo.bean.Photo;
import com.redrose.audioandvideo.databinding.ActivityPrePhotoBinding;
import com.redrose.audioandvideo.pagetransformer.RotateDownPageTransformer;
import com.redrose.audioandvideo.ui.activitys.BaseActivity;
import com.redrose.audioandvideo.utils.GlideUtil;
import com.redrose.audioandvideo.widget.ResizableImageView;

import java.util.List;

public class PrePhotoActivity extends BaseActivity<ActivityPrePhotoBinding> {
    private int mCurrentMax;
    private List<Photo> mPhotoList;
    private ImagePagerAdapter mAdapter;
    @Override
    public void initData() {
        mPhotoList = (List<Photo>) getIntent().getBundleExtra("data").getSerializable("photoList");
        mCurrentMax = mPhotoList.size();
        initAdapter();
    }
    private void initAdapter() {
        mAdapter = new ImagePagerAdapter();
        mBinding.vpPrePhoto.setAdapter(mAdapter);
        /** 翻页动画设置 */
        /*mViewPager.setPageTransformer(false,new ZoomOutPageTransformer());*/
        /*mViewPager.setPageTransformer(false,new DepthPageTransformer());*/
        mBinding.vpPrePhoto.setPageTransformer(false, new RotateDownPageTransformer());
        mBinding.vpPrePhoto.setCurrentItem(0);
    }

    @Override
    public int setLayout() {
        return R.layout.activity_pre_photo;
    }
    private class ImagePagerAdapter extends PagerAdapter {

        @Override
        public int getCount() {

            return mCurrentMax;
        }

        @Override
        public boolean isViewFromObject(View view, Object object) {
            return view == object;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            View view = LayoutInflater.from(mContext).inflate(R.layout.image_viewpager_item, null);
            ResizableImageView imageView = view.findViewById(R.id.resize_image);
            GlideUtil.loadImage(PrePhotoActivity.this,mPhotoList.get(position).getPath(),imageView);
            container.addView(view);
            return view;
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View) object);
        }
    }
}
